/*{{page.name}}Ctrl.js*/
(function(app){
    'use strict';
    app.controller('{{page.name}}Ctrl', ['$scope', '$http','conowModals','OperationService','$stateParams','{{entitySubName}}Service','activitiService',
        function($scope, $http ,conowModals,OperationService,$stateParams,{{entitySubName}}Service,activitiService) {
            var vm = $scope.vm = {};
            vm.isEdit = false;
            vm.dataId = $stateParams.ID;
            vm.TABLE_NAME = $stateParams.TABLE_NAME;
            vm.TABLE_ID = $stateParams.TABLE_ID;

            //初始化
            var init = function () {
                {{entitySubName}}Service.queryById(vm.dataId).success(function (data) {
                    if(data.success){
                        vm.data = data.obj;
                    }
                })
            };

            if(vm.dataId){
                init();
                vm.isEdit = true;
            }

            /**
             * 保存修改
             */
            vm.saveOrUpdate = function(){
                {{entitySubName}}Service.saveOrUpdate(vm.data).then(function(data){
                    
                })
            };
             {% if hasWorkflow %}
            /**
             * 暂存修改
             */
            vm.saveTemp = function(){
                {{entitySubName}}Service.saveTemp(vm.data).then(function(data){
                    
                })
            };


             /**
             * 启动流程
             */
            vm.startFlow = function(){
                {{entitySubName}}Service.startFlow(vm.data).then(function(data){

                })
            };
             {% endif %}
            
            /**
             * 删除数据
             */
            vm.delete = function(){
                {{entitySubName}}Service.deleteById(vm.data.ID).then(function(data){

                });
            }

        }]);
})(app)
